package com.scs.application.modules.cfg.adapter;

import com.scs.application.modules.cfg.service.ParameterService;
import com.scs.application.modules.sys.properties.SystemProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:参数适配器
 */
@Component
public class ParameterAdapter {
    @Autowired
    private SystemProperties systemProperties;

    private List<ParameterService> parameterServices;

    @Autowired
    private void setParameterServices(List<ParameterService> parameterServices) {
        this.parameterServices = parameterServices;
    }

    /**
     * 获取当前项目的Parameter实现类
     * @return
     */
    public ParameterService getParameterService() {
        ParameterService parameterService = null;
        for(ParameterService paraService : parameterServices) {
            if (paraService.isSupport(systemProperties.getFlagProject())) {
                parameterService = paraService;
                break;
            }
        }
        return parameterService;
    }

    /**
     * 根据类型获取Parameter实现类
     * @param flagProject
     * @return
     */
    public ParameterService getParameterService(Boolean flagProject) {
        ParameterService parameterService = null;
        for(ParameterService paraService : parameterServices) {
            if (paraService.isSupport(flagProject)) {
                parameterService = paraService;
                break;
            }
        }
        return parameterService;
    }
}
